<!--  Nguyen Huu Nhat -->
<?php
@session_start();
include '../DataBase/ConnectDB.php';
include '../Security/CheckAdmin.php';
include '../Home/DefineVar.php';
mysql_select_db(MYSQL_DATABASE, $link)
or exit('Could not select database'.mysql_error());
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
////////////////////////////////////////////////////////////////////////
$roomName = mysql_real_escape_string($_POST['roomName']);
$chairNumber = mysql_real_escape_string($_POST['chairNumber']);
$useFee = mysql_real_escape_string($_POST['useFee']);
$cancelFee = mysql_real_escape_string($_POST['cancelFee']);
$fineFee =mysql_real_escape_string($_POST['fineFee']);
$orderFee =mysql_real_escape_string($_POST['orderFee']);
$cancelFeeAll = mysql_real_escape_string($_POST['cancelFeeAll']);
$orderFeeAll = mysql_real_escape_string($_POST['orderFeeAll']);
$fineFeeAll = mysql_real_escape_string($_POST['fineFeeAll']);
//作成された会議室はデータベースに記録される。
$query = "SELECT * FROM ".MYSQL_TABLE_ROOMINFOR." WHERE roomname='$roomName';";
$result = mysql_query($query, $link);
if(!$result){
	print("<br><script type='text/javascript'> alert('".SQL_ERR_MESS."'); window.location ='CreateRoom.php';</script> ");
	exit();
}
if(($resultuser = mysql_fetch_row($result)) != false){
	print("<br><script type='text/javascript'> alert('".CRE_ROOM_ERR_MESS."'); window.location ='CreateRoom.php';</script> ");
	exit();
}

$query = "INSERT INTO ".MYSQL_TABLE_ROOMINFOR."(roomname, seatnumber, usingcost, fineFee, cancelfee, orderfee) VALUES('$roomName', '$chairNumber', '$useFee', '$fineFee', '$cancelFee', '$orderFee');";
// print($query);
if(($result = mysql_query($query, $link))){
	print("<br><script type='text/javascript'> alert('".CRE_ROOM_OK_MESS."'); window.location ='CreateRoom.php';</script> ");
}
else{
	print("<br><script type='text/javascript'> alert('".SQL_ERR_MESS."'); window.location ='CreateRoom.php';</script> ");
	exit();
}
if($cancelFeeAll){
	mysql_query("UPDATE ".MYSQL_TABLE_ROOMINFOR." SET cancelfee ='".$cancelFee."';",$link);
}
if($orderFeeAll){
	mysql_query("UPDATE ".MYSQL_TABLE_ROOMINFOR." SET orderfee ='".$orderFee."';",$link);
}
if($fineFeeAll){
        	mysql_query("UPDATE ".MYSQL_TABLE_ROOMINFOR." SET finefee ='".$fineFee."';",$link);
        }
 mysql_close($link);
?>
</body>
</html>